feat(auth): add support for error codes and refactor AuthError
#518
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
This PR includes some changes on Auth error system, I tried my best to keep it compatible and without breaking changes.
If you see anything that could be a breaking change, please let me know.
What is the new behavior?
Error codes
Introduce
ErrorCode
type as a raw representable string, added static properties for each of the known error codes. Since error codes are raw representable strings, if an unknown error code is returned, decoding is going to work fine.Deprecated errors
missingExpClaim
error deprecated, it is never thrown now, but I kept it for retro-compatibilitymalformedJWT
error deprecated, it is never thrown now, but I kept it for retro-compatibilitysessionNotFound
error deprecated, usesessionMissing
insteadpkce(_:)
error deprecated, usepkceGrantCodeExchange
insteadinvalidImplicitGrantFlowURL
error deprecated, useimplicitGrantRedirect
insteadmissingURL
error deprecated, it is never thrown, but I kept it for retro-compatibilityapi(_:)
error deprecated, useapi(message:errorCode:underlyingData:underlyingResponse:)
insteadAdded errors
sessionMissing
thrown when a session is required to proceed, but none was found, either thrown by the client, or returned by the server.weakPassword
thrown when password is deemed weak, check associated reasons to know why.api(message:errorCode:underlyingData:underlyingResponse:)
thrown by API when an error occurs, checkerrorCode
to know more, or useunderlyingData
orunderlyingResponse
for access to the response which originated this error.pkceGrantCodeExchange
thrown when an error happens during PKCE grant flow.implicitGrantRedirect
thrown when an error happens during implicit grant flow.